<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'资源添加', styles:'bootstrap,font-awesome,animate,style,dtvalidate,layer,chosen,layui'}){%>
    <style type="text/css">
        body{padding-top:10px;}
    </style>
    <%}%>
</head>
<body>
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="col-sm-offset-1 col-sm-10" style="margin-left: -10px;width: 100%;">
                <button type="button" class="return-btn btn btn-w-m btn-primary">返回</button>
                <div style="border-color: #e7eaec;border-image: none;border-style: solid solid none;border-width: 4px 0px;padding-bottom: 15px;margin-top: 10px;" ></div>
            </div>
        </div>
    </div>
</div>
<!-- START 内容部分 -->
<div class="container" >
    <form class="form-horizontal" id="info-form" method="post" autocomplete="off" style="margin: auto">
        <input type="hidden" id="id" name="id" value="${design.id}"  class="form-control" />
        <input type="hidden" id="designCompleteName" name="designCompleteName" value="${user.userRealname}"  class="form-control" />
        <div class="form-group">
            <label class="control-label col-sm-2">状态:</label>
            <div class="col-sm-2">
                <select id="designStatus" selected="${design.designStatus}" name="designStatus" class="form-control">
                    <option value="">全部分类</option>
                    <option value="1">未开始</option>
                    <option value="2">进行中</option>
                    <option value="3">已完成</option>
                    <option value="4">已取消</option>
                </select>
            </div>
        </div>
        <div class="form-group started">
            <label class="control-label col-sm-2">原CTR:</label>
            <div class="col-sm-6">
                <input id="designOldCtr" name="designOldCtr" value="${design.designOldCtr}" class="form-control" onkeyup="value=value.replace(/[^\d?.{1}\d{2}]/g,'')" ></intput>
            </div>
        </div>

        <div class="form-group started">
            <label class="control-label col-sm-2">设计数量:</label>
            <div class="col-sm-6">
                <input id="designNumber" name="designNumber" value="${design.designNumber}" maxlength="3" onkeyup="value=value.replace(/[^\d?.{1}\d{2}]/g,'')" class="form-control"></intput>
            </div>
        </div>
        <div class="form-group started">
            <label class="control-label col-sm-2">是否来样:</label>
            <div class="col-sm-6">
                <select id="designToSample" name="designToSample" class="form-control">
                    <option value="">请选择</option>
                    <option value="是">是</option>
                    <option value="否">否</option>
                </select>
            </div>
        </div>
        <div class="form-group started">
            <label class="control-label col-sm-2">预计样品到期日:</label>
            <div class="col-sm-6">
                <input type="text" id="designSampleExpiry" name="designSampleExpiry" value="${design.designSampleExpiry}" placeholder="请选择预计样品到期日" class="form-control">
            </div>
        </div>
        <div class="form-group started">
            <label class="control-label col-sm-2">预计完成时间:</label>
            <div class="col-sm-6">
                <input type="text" id="designExpect" name="designExpect" value="${design.designExpect}" placeholder="请选择预计完成时间" class="form-control">
            </div>
        </div>

        <div class="form-group attachment">
            <label class="control-label col-sm-2">请选择实际完成时间:</label>
            <div class="col-sm-6">
                <input type="text" id="designComplete" name="designComplete" placeholder="请选择实际完成时间" class="form-control">
            </div>
        </div>
        <div class="form-group attachment">
            <label class="control-label col-sm-2">附件:</label>
            <div class="col-sm-2">
                <a class="club-import-btn">
                    <input type="file" id="importSession" name="importSession">
                </a>
                <input type="hidden" name="designAttachment" id="designAttachment">
            </div>
        </div>
        <div class="form-group remark">
            <label class="control-label col-sm-2">备注:</label>
            <div class="col-sm-6">
                <textarea id="designRemark" name="designRemark" class="form-control" rows="3"></textarea>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button type="button" class="save-btn btn btn-primary">
                    <i class="fa fa-save"></i> 保存
                </button>
            </div>
        </div>
    </form>
</div>
<!-- END 内容部分 -->

<!-- START 公共脚本 -->
<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,dtvalidate,dtvalidate-lang-zh_cn,laydate,layer,chosen'}){}%>
<!-- END 公共脚本 -->
<script>
    $("#importSession").on("change",function(){
        var formFile = new FormData($('#info-form')[0]);
        var index=layer.load(1, {
            shade: [0.1,'#fff'],
            zIndex : 1111//0.1透明度的白色背景
        });
        $.ajax({
            url: "/upload/uploadFile",
            data: formFile,
            type: "post",
            processData: false,//用于对data参数进行序列化处理 这里必须false
            contentType: false, //必须
            success: function (data) {
                if(data.ok){
                    parent.layer.msg("上传成功！",{icon: 0,time:1500,shade: [0.8, '#393D49']});
                    $("#designAttachment").val(data.data);
                    layer.close(index);
                }else{
                    parent.layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }
            },
        });
    });

    var cvalidator;
    $(function(){
        $(".remark").hide();
        $(".attachment").hide();
        $(".started").hide();
        laydate.render({
            elem: '#designSampleExpiry' //指定元素
            ,trigger: 'click'
        });
        laydate.render({
            elem: '#designComplete' //指定元素
            ,trigger: 'click'
        });
        laydate.render({
            elem: '#designExpectNew' //指定元素
            ,trigger: 'click'
        });
        laydate.render({
            elem: '#designExpect' //指定元素
            ,trigger: 'click'
        });


        //初始化验证器
        cvalidator = $.fn.dlshouwen.validator.init($('#info-form'));
        $("#designStatus").change(function () {
            var designStatus=$("#designStatus").val();
            if(designStatus==1||designStatus==2){
                $(".started").show();
                $(".remark").hide();
                $(".attachment").hide();
            }else if(designStatus==4){
                $(".remark").show();
                $(".attachment").hide();
                $(".started").hide();
            }else if(designStatus==3) {
                $(".remark").show();
                $(".attachment").show();
                $(".started").hide();
            }else{
                $(".remark").hide();
                $(".attachment").hide();
                $(".started").hide();
            }
        });
        //提交表单
        $('.save-btn').on('click',function(){
            var designStatus=$("#designStatus").val();
            var designAttachment=$("#designAttachment").val();
            var designRemark=$("#designRemark").val();
            var designOldCtr=$("#designOldCtr").val();
            var designToSample=$("#designToSample").val();
            var designSampleExpiry=$("#designSampleExpiry").val();
            var designShootNumber =$("designShootNumber").val();
            var designNumber=$("#designNumber").val();
            var designComplete=$("#designComplete").val();
            if(designStatus==''){
                parent.layer.msg('请先选择状态！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }else if(designStatus==1||designStatus==2){
                if(designOldCtr==''){
                    parent.layer.msg('请填写原CTR！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                    return;
                }else if(designShootNumber=''){
                    parent.layer.msg('请填写拍摄数量！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                    return;
                }else if(designNumber==''){
                    parent.layer.msg('请填写设计数量！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                    return;
                }else if(designToSample==''){
                    parent.layer.msg('请选择是否来样！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                    return;
                }else if(designSampleExpiry==''){
                    parent.layer.msg('请选择预计样品到期日！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                    return;
                }
            }else if(designStatus==3){
                if(designComplete==''){
                    parent.layer.msg('请选择实际完成时间！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                    return;
                }
            }else if(designStatus==4 && designRemark==''){
                parent.layer.msg('请填写取消原因！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }
            layer.confirm('一经修改,无法恢复,确定要修改当前状态？', {
                btn: ['确定','取消'],title:'提示'
            }, function(){
                //数据提交
                $.post('/sea/design/usave.do',$('#info-form').serialize(),function(data){
                    if( data.ok ){
                        parent.layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']}, function(){
                            parent.$relatedTable.bootstrapTable('refresh');
                            parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭弹窗
                        });
                    }else{
                        parent.layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
                    }
                });
            });


        });
        //返回
        $('.return-btn').on('click',function(){
            parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭弹窗
        });
        $("#designStatus").find("option[value='${design.designStatus}']").attr("selected",true);
        $("#designStatus").change();
        $("#designToSample").find("option[value='${design.designToSample}']").attr("selected",true);
        $("#designToSample").change();
    });
</script>
</body>
</html>